import java.awt.event.*;
import javax.swing.*;

public class MoveToShortButton extends JButton{
	//	Local Variables
	private JFrame _parentFrame;
	private StoreLogic _logic;
	private FloorPanel _somethingP;
	
	public MoveToShortButton(JFrame aParentFrame, StoreLogic alogic, FloorPanel aSomethingP)
	{
		super("Move to shortest queue");
		_parentFrame = aParentFrame;
		_logic = alogic;
		_somethingP = aSomethingP;
		this.addActionListener(new MoveToShortListener());
	}
	
	private class MoveToShortListener implements ActionListener 
	{
		public void actionPerformed(ActionEvent e) 
		{	//	Checks so that the store floor isnt empty.
			if (_logic.getNotInLine().isEmpty())
			{
				JOptionPane.showMessageDialog(_parentFrame, "There are no customers in the store.","Error", 1);
			}	// Checks if the user has selected a customer
			else if (_somethingP.getSelectedCustomer() < 0)
			{
				JOptionPane.showMessageDialog(_parentFrame, "You have not selected a customer.","Error", 1);
			}
			else	// Move to shortest line
			{
				_logic.moveCustToQueue(_somethingP.getSelectedCustomer(),_logic.checkShortLine());
			}	
		}
	}
}
